package com.gali.mall.common;

import com.gali.mall.exception.GaLiException;
import com.gali.mall.exception.GaLiExceptionEnum;
import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class Const {
    public static final String MD5_CODE="sdfsdgsdgsdgsdgs";
    public static final String USER_NAME="username";
    public static String FILE_UPLOAD_DIR;

    @Value("${file.upload.dir}")
    public void setUploadFileDir(String fileDir){
        FILE_UPLOAD_DIR=fileDir;
    }
    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC= Sets.newHashSet("price desc","price asc");
    }
    public interface ProductStatus{
        public static final int STATUS=1;
        public static final int NO_STATUS=0;
    }
    public interface ProductSelected{
        public static final int SELECTED=1;
        public static final int NO_SELECTED=0;
    }
    public enum OrderStatusEnum{
        CANCELED(0,"用户已取消"),
        NOT_PAY(10,"未付款"),
        PAY(20,"已付款"),
        DELIVERED(30,"已发货"),
        FINISH(40,"已完成交易");
        private String value;
        private int code;
        OrderStatusEnum(int code,String value){
            this.code=code;
            this.value=value;
        }
        public String getValue() {
            return value;
        }
        public void setValue(String value) {
            this.value = value;
        }
        public int getCode() {
            return code;
        }
        public void setCode(int code) {
            this.code = code;
        }
        //通过code返回
        public static OrderStatusEnum codeOf(int code){
            for (OrderStatusEnum orderStatusEnum:values()){
                if (orderStatusEnum.getCode()==code){
                    return orderStatusEnum;
                }
            }
            throw new GaLiException(GaLiExceptionEnum.ORDER_STATUS_NOT_EXIST);
        }

    }
}
